#include <stdio.h>
#include <string.h>
#include <json/json.h>
struct info{
    int ID;
    char name[20];
    int age;
};
int main(){

    struct info pag[20];
    pag[0].age=20;
    strcpy(pag[0].name,"wangxiaodong");
    pag[0].ID=1;
    pag[1].age=22;
    strcpy(pag[1].name,"wangxiaodong");
    pag[1].ID=2;
    struct info message1={1,"waaddasd",20};
    struct info message2={2,"xxxxxx",30};
    struct info message3={3,"yyyyyy",60};
    struct info arr[3]={message1,message2,message3};
    struct info brr[100];
    struct json_object * arr1=json_object_new_array();
    struct json_object * json_ID1;
    struct json_object * json_name1;
    struct json_object * json_age1;
    for(int i=0;i<3;i++){
        struct json_object * obj=json_object_new_object();
        json_ID1 =json_object_new_int (arr[i].ID);
        json_name1=json_object_new_string (arr[i].name);
        json_age1 =json_object_new_int (arr[i].age);
        json_object_object_add (obj, "ID1",json_ID1);
        json_object_object_add (obj, "name1",json_name1);
        json_object_object_add (obj, "age1",json_age1);
        json_object_array_add (arr1,obj);  
    }
    const char * json_struct=json_object_to_json_string(arr1);
    printf("%s\n",json_struct);
   
    
    struct json_object*	recv=json_tokener_parse(json_struct);
    int idx=json_object_array_length (recv);
    struct json_object * json_new_id1;
    struct json_object * json_new_name1;
    struct json_object * json_new_age1;
    int j=0;
    for(j=0;j<idx;j++){
    struct json_object *js= json_object_array_get_idx(recv,j);//其中j表示的是第几个{}，而不是整个的长度，
    json_new_id1=json_object_object_get (js,"ID1");
    json_new_name1=json_object_object_get (js,"name1");
    json_new_age1=json_object_object_get (js,"age1");

   
    brr[j].ID=json_object_get_int(json_new_id1);
    strcpy(brr[j].name,json_object_get_string (json_new_name1));
    brr[j].age=json_object_get_int(json_new_age1);
     printf("%d %s %d\n",brr[j].ID,brr[j].name,brr[j].age);
    }

    printf("%d",idx);
    return 0;
}